package com.itheima.service.impl;

import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    //查询全部
    @Override
    public List<Dept> list() {
        List<Dept> depts = deptMapper.list();
        return depts;
    }

    //删除
    @Override
    public Boolean deleteById(Integer id) {
        int rows = deptMapper.deleteById(id);
        if (rows > 0) {
            return true;
        }
        return false;
    }

    //新增
    @Override
    public Boolean save(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        int rows = deptMapper.save(dept);
        if (rows > 0) {
            return true;
        }
        return false;
    }

    @Override
    public Dept getById(Integer id) {
        return deptMapper.getById(id);
    }

    @Override
    public void update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }


}
